﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace CoolCode.Web.UI
{
    public class Partial<T> : UserControl, IPartial<T>
    {
        public T Model { get; set; }

        protected override void Render(HtmlTextWriter writer)
        {
            if (this.Model == null )//|| this.Model.Count == 0)
            {
                writer.Write("<br/>");
                return;
            }
            base.Render(writer);
        }

        public virtual void SetProperty(string key, object value)
        {
            this.ViewState[key] = value;
        }

        public virtual T GetProperty (string key)
        {
            return  this.GetProperty (key, default(T));
        }

        public virtual T GetProperty (string key, T defaultValue)
        {
            return this.ViewState[key] == null ? defaultValue : (T)this.ViewState[key];
        }
    }

    public interface IPartial<T>
    {
        T Model { get; set; }
        void DataBind();
    }
}
